<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var findPeakElement = function(nums) {
    if( nums.length == 1 ){
        return 0
    }
    if( nums.length == 2 ){
        return (nums[0]>nums[1])?0: 1
    }
    if( nums.length>2 ){
        if( nums[0]>nums[1] ){
            return 0
        }
        if( nums[nums.length-1]>nums[nums.length-2] ){
            return nums.length-1
        }
    }
    for( var i = 1 ; i<nums.length-1 ; i++ ){
        if( nums[i]>nums[i-1] && nums[i]>nums[i+1] ){
            return i
        }
    }
};
var nums = [1,2]
console.log(findPeakElement(nums))
    </script>
</body>
</html>